<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.1.3/axios.js"></script>
    <script>
        // fetch两段then
        // axios一端then

        // fetch get 请求
        // get delete 无body
        fetch('http://122.9.139.38:4000/ping?')
            .then(res => res.text())
            .then(res => console.log(res))

        axios({
            url: 'http://122.9.139.38:4000/ping?'
        })
            .then(res => console.log(res.data))

        // put post 有 body
        fetch('http://122.9.139.38:4000/books', {
            method: 'post',
            headers: {
                'content-type': 'application/json'
            },
            body: JSON.stringify({
                author: 'test author',
                publisher: 'test publisher',
                bookname: 'test bookname'
            })
        })
            .then(res => res.json())
            .then(res => console.log(res))

        axios({
            url: 'http://122.9.139.38:4000/books',
            method: 'POST',
            data: {
                author: 'test author',
                publisher: 'test publisher',
                bookname: 'test bookname'
            }
        })
            .then(res => console.log(res))
    </script>
</body>

</html>